﻿/* * 版 本 PIT-ADMS V7.0.3 敏捷开发框架
 * Copyright (c) 2013-2018 Hexagon PPM
 * 创建人：chenkai
 * 日  期：2022-02-24
 * 描  述：属性设置
 */
var refreshGirdData;
var curDrawingCatalogueID = "";
var DrawingCatalogueID = request('DrawingCatalogueID');
var selectData = [];
var ProjectId = request('ProjectId');
var relrtree; //初始化树形
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.bind();
            page.initGird();
        },
        bind: function () {
            $('#SelectProjectId').lrselect({
                allowSearch: true,
                url: top.$.rootUrl + '/ZZDT_EC/ec_project/GetProjectSelectList',
                param: {},
                value: 'ProjectId',
                text: 'ProjectName',
                title: 'ProjectName',
                select: function (item) {
                    relrtree();
                    curDrawingCatalogueID = '';
                    page.search();
                }
            });

            //查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 保存
            $('#lr_save').on('click', function () {
                var postData = {
                    strEntity: JSON.stringify(selectData)
                }
                $.lrSaveForm(top.$.rootUrl + '/ZZDT_EC/ec_drawing_file/SaveSelectData?drawingCatalogueID=' + DrawingCatalogueID + "&ProjectId=" + ProjectId, postData, function (res) {

                });
            });
        },
        // 初始化列表
        initGird: function () {
            $('#gridtable').jfGrid({
                url: top.$.rootUrl + '/ZZDT_EC/ec_drawing_file/GetPageList',
                headData: [
                    { label: "图纸文件名称", name: "DrawingFileName", width: 300, align: "left", sort: false },
                    { label: "图纸类型", name: "DrawingTypeName", width: 100, align: "center", sort: false },
                    { label: "图纸阶段", name: "DrawingStageName", width: 100, align: "center", sort: false },
                    { label: "所属系统", name: "DrawingSystemName", width: 100, align: "center", sort: false },
                    { label: "版本", name: "FileVersion", width: 80, align: "center", sort: false },
                    { name: "", width: 1, sort: false }
                ],
                mainId: 'DrawingFileID',
                isPage: true,
                isMultiselect: true,
                onSelectRow: function (rowData, isSelect) {
                    selectData = $.grep(selectData, function (item) {
                        return item.DrawingFileID != rowData.DrawingFileID || item.ProjectId != $('#SelectProjectId').lrselectGet();
                    });
                    if (isSelect) {
                        var param = {};
                        param.ProjectId = $('#SelectProjectId').lrselectGet();
                        param.DrawingFileID = rowData.DrawingFileID;
                        selectData.push(param);
                    }
                },
                onRenderComplete: function (data) {
                    //默认已经选中的
                    for (var i = 0; i < data.length; i++) {
                        if (selectData) {
                            var gdata = $.grep(selectData, function (item) {
                                return item.DrawingFileID == data[i].DrawingFileID && item.ProjectId == $('#SelectProjectId').lrselectGet();
                            });
                            if (gdata && gdata.length > 0) {
                                $('#gridtable').jfGridSet("selectRow", data[i].DrawingFileID);
                            }
                        }
                    }
                }
            });
            //page.search();
        },
        search: function (param) {
            param = param || {};
            param.DrawingCatalogueID = curDrawingCatalogueID;
            param.ProjectId = $('#SelectProjectId').lrselectGet();
            param.DrawingFileName = $("#DrawingFileName").val();
            $('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
        }
    };
    refreshGirdData = function () {
        $('#gridtable').jfGridSet('reload');
    };
    relrtree = function () {
        // 初始化左侧树形数据
        $('#dataTree').lrtree({
            url: top.$.rootUrl + '/ZZDT_EC/ec_drawing_catalogue/GetTreeData',
            param: { ProjectId: $('#SelectProjectId').lrselectGet() },
            nodeClick: function (item) {
                curDrawingCatalogueID = item.value;
                $("#titleinfo").html(item.text);
                page.search();
            }
        });
    };
    page.init();
}